﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;

namespace FillColor.VisualWebPart1
{
    public partial class VisualWebPart1UserControl : UserControl
    {

        
        private static SPWeb web;
        private static SPList list;
        private static SPList bilder;
        
        protected void Button1_Click(object sender, EventArgs e)
        {
            web = SPContext.Current.Web;
            try
            {
                list = web.Lists["Testbibliothek_Managed_Metadata"];
                //bilder = web.Lists["Bilder"];
                //string blau = String.Format("{0}/{1}", web.Url, bilder.Items[0].File.ToString());
                //string turkis = String.Format("{0}/{1}", web.Url, bilder.Items[1].File.ToString());
                //string violett = String.Format("{0}/{1}", web.Url, bilder.Items[2].File.ToString());
                //string orange = String.Format("{0}/{1}", web.Url, bilder.Items[3].File.ToString());
                //string puzzle = String.Format("{0}/{1}", web.Url, bilder.Items[4].File.ToString());

                string blau = "<img src=\"/PublishingImages/b.png\"/>";
                string orange = "<img src=\"/PublishingImages/o.png\"/>";
                string turkis = "<img src=\"/PublishingImages/t.png\"/>";
                string violett = "<img src=\"/PublishingImages/v.png\"/>";
                string white = "<img src=\"/PublishingImages/w.png\"/>";

                //string blau = "<img src=\"/Bilder/b.png\"/>";
                //string orange = "<img src=\"/Bilder/o.png\"/>";
                //string turkis = "<img src=\"/Bilder/t.png\"/>";
                //string violett = "<img src=\"/Bilder/v.png\"/>";
                //string white = "<img src=\"/Bilder/w.png\"/>";

                //foreach (SPItem item in list.Items)
                //{
                //    item["o"] = String.Empty;
                //    item["t"] = String.Empty;
                //    item["v"] = String.Empty;
                //    item["b"] = String.Empty;
                //}
      
      
                foreach (SPItem item in list.Items)
                {
                    item["html"] = String.Empty;
                    item.Update();
                }

                foreach (SPItem item in list.Items)
                {
                    //if (item["Dokumentenzugehörigkeit"] != null)
                    //{
                    //    item["puzzle2"] = puzzle;
                    //}

                    string farbe = String.Empty;

                    if (item["Produktkategorie"] != null)
                    {
                        if (String.IsNullOrEmpty(item["Produktkategorie"].ToString()))
                        {
                            farbe += white;
                        }
                        else
                        {
                            farbe += blau;
                        }
                    }

                    if (item["Projektnummer"] != null)
                    {
                        if (String.IsNullOrEmpty(item["Projektnummer"].ToString()))
                        {
                            farbe += white;
                        }
                        else
                        {
                            farbe += orange;
                        }
                    } 

                    if (item["Kunde"] != null)
                    {
                        if (String.IsNullOrEmpty(item["Kunde"].ToString()))
                        {
                            farbe += white;
                        }
                        else
                        {
                            farbe += turkis;
                        }
                    } 

                    if (item["Prozess"] != null)
                    {
                        if (String.IsNullOrEmpty(item["Prozess"].ToString()))
                        {
                            farbe += white;
                        }
                        else
                        {
                            farbe += violett;
                        }
                    }

                    item["html"] = farbe;
                    item.Update();
                }
            }
            catch (Exception ex)
            {

                txt_message.Text = ex.Message;
            }


            txt_message.Text = "Viola";
            //list.Fields["blau"].Title = "b";
            //list.Fields["blau"].Update();
            //list.Fields["orange"].Title = "o";
            //list.Fields["orange"].Update();
            //list.Fields["turkis"].Title = "t";
            //list.Fields["turkis"].Update();
            //list.Fields["violett"].Title = "v";
            //list.Fields["violett"].Update();
           
        }
    }
}
